package cn.credit.loan.controller;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
 * 还款信息记录控制类
 * @author 
 *
 */
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.credit.loan.entity.Repayment;
import cn.credit.loan.service.repayment.RepaymentService;
@Controller
public class RepaymentController {
	//日志输出
	private Logger logger = Logger.getLogger(RepaymentController.class);
	//注入
	@Autowired
	private RepaymentService repaymentService;
	
	/**
	 * 前台客户进行还款页面
	 * @return
	 */
	@RequestMapping(value="/reversionpay")
	public ModelAndView repay(){
		logger.info("####--------->> ");
		return new ModelAndView("front/reversion");
	}
	
	/**
	 * 还款记录信息添加
	 * @param repayment
	 * @param model
	 * @return
	 */
	@RequestMapping("/repaymentadd")
	public String getRepaymentAdd(Repayment repayment,ModelMap model)
	{
		try {
			repayment.setRepaymentDate(new Date());
			repayment.setRepaymentPrincipal(3000.00);
			repayment.setRepaymentInterest(300.00);
			repayment.setRepaymentMoney(490.00);
			repayment.setRepaymentNumbers("4");
			repayment.setStateId(1);
			boolean repaymentadd=repaymentService.getRepaymentAdd(repayment);
			if(repaymentadd)
			{
				return "RepaymentAdd";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
		
	}
	
	/**
	 * 还款信息更新
	 * @param repayment
	 * @param model
	 * @return
	 */
	@RequestMapping("/repaymentupdate")
	public String getRepaymentUpdate(Repayment repayment,ModelMap model)
	{
		try {
			repayment.setContId(1);	
			repayment.setRepaymentDate(new Date());
			repayment.setRepaymentPrincipal(3000.00);
			repayment.setRepaymentInterest(300.00);
			repayment.setRepaymentMoney(490.00);
			repayment.setRepaymentNumbers("4");
			repayment.setStateId(1);
			boolean repaymentupdate=repaymentService.getRepaymentUpdate(repayment);
			if(repaymentupdate)
			{
				return "RepaymentUpdate";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
		
		
	}
	
	/**
	 * 还款记录信息删除
	 * @param repaymentId
	 * @param model
	 * @return
	 */
	@RequestMapping("/repaymentdelete")
	public String getRepaymentDelete(int repaymentId,ModelMap model)
	{
		try {
			boolean repaymentdelete=repaymentService.getRepaymentDelete(repaymentId);
			if(repaymentdelete)
			{
				return "RepaymentDelete";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
		
		
	}
	
	/**
	 * 还款记录信息查询
	 * @param repayment
	 * @param model
	 * @return
	 */
	@RequestMapping("/repaymentlist")
	@ResponseBody
	public List<Repayment> getRepaymentList(Repayment repayment,ModelMap model)
	{
		
		try {
			List<Repayment> repaymentlist = repaymentService.getRepaymentList(repayment);
			if(repaymentlist!=null)
			{
				return repaymentlist;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	
	}
}
